/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import entity.Action;
import entity.User;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

/**
 *
 * @author daz
 */
public class DataController implements Controller {

    List<Action> listActions = new LinkedList<Action>();

    @Override
    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        HashMap<String, Object> map = new HashMap<String, Object>();
        User user = new User();
        user.setName("admin");
        putAction(user.getName());
        String now = (new Date()).toString();
        map.put("name", user.getName());
        map.put("now", now);
        map.put("action", listActions);
        return new ModelAndView("data", "map", map);
    }

    private void putAction(String role) {
        listActions = new LinkedList<Action>();
        Action studentData = new Action("student.htm", "Input student data");
        Action showStudent = new Action("showstudent.htm", "Show student data");
        Action professorData = new Action("professor.htm", "Input professor data");
        Action showProfessor = new Action("showprofessor.htm", "Show professor data");
        Action roomData = new Action("room.htm", "Input room data");
        Action timeData = new Action("slot.htm", "Input time slot data");
        Action sheduler = new Action("sheduler.htm", "Shedule defense");
        listActions.add(professorData);
        listActions.add(showProfessor);
        listActions.add(studentData);
        listActions.add(showStudent);
        listActions.add(roomData);
        listActions.add(timeData);
        listActions.add(sheduler);
    }
}
